home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap7 / 7_1 / ht71b.pl < prev    next >
Encoding:
Perl Script  |  1996-06-15  |  1.5 KB  |  85 lines

  1. #!/usr2/local/bin/perl -w
  2.  
  3. require "cgilib.pl";
  4.  
  5. #
  6. # Configurable Variables
  7. #
  8. $SENDMAIL = '/usr/bin/sendmail';
  9. $TO       = 'kgr';
  10. $SUBJECT  = 'Survey Results';
  11. $BACK     = '<A HREF="/kgr/book">Back to my Homepage</A>';
  12. @FIELDS   = qw(name email street city state zip rating comments);
  13.  
  14. # Output the HTML content type
  15. print "Content-type: text/html\n\n";
  16.  
  17. # Initialize a hash of CGI arguments using
  18. # routines from cgilib.pl
  19. readParse(*dict);
  20.  
  21. # Build the 'from' address of the form:
  22. #     "email address, (real name)"
  23. my $from  = "$dict{email}, ($dict{name})";
  24.  
  25. # The -t causes the To: field to be read from standard input
  26. # instead of being expected on the command line.  The -oi
  27. # prevents a dot on a line by itself from being interpreted
  28. # as a message terminator.
  29. open  MAIL, "|$SENDMAIL -t -oi";
  30.  
  31. # Output the mail header
  32. print MAIL <<EOMH;
  33. Reply-to: $from 
  34. From: $from
  35. To: $TO
  36. Subject: $SUBJECT
  37.  
  38. EOMH
  39.  
  40. # Output the mail body
  41. foreach (@FIELDS)
  42. {
  43.     print MAIL "<", uc($_), ">\n $dict{$_}\n\n";
  44. }
  45.  
  46. # Output the mail footer
  47. print MAIL <<EOMF;
  48.  
  49. <REMOTE HOST>
  50. $ENV{'REMOTE_HOST'}
  51.  
  52. <REMOTE ADDRESS>
  53. $ENV{'REMOTE_ADDR'}
  54.  
  55. <USER AGENT>
  56. $ENV{'HTTP_USER_AGENT'}
  57.  
  58. EOMF
  59.  
  60. # Close the pipe, sending the mail
  61. close MAIL;
  62.  
  63. # Generate HTML notification
  64. print <<EOH;
  65. <HTML><BODY>
  66. <H1>Thanks!</H1>
  67. Your comments have been noted.<BR>
  68. <BR>
  69. Your response:
  70. <TABLE>
  71. EOH
  72.  
  73. # Output the mail body
  74. foreach (@FIELDS)
  75. {
  76.     $val = $dict{$_};
  77.     $val =~ s/</</g;
  78.     $val =~ s/>/>/g;
  79.     print qq{<TR><TH ALIGN="LEFT">}, uc($_), "<TD>$dict{$_}<BR>";
  80. }
  81.  
  82. print "</TABLE><BR>$BACK</BODY></HTML>";
  83.  
  84. 1;
  85.